﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        admin_user.Visible = false;
        admin_forum.Visible = false;
        admin_group.Visible = false;


        CGeneral.CheckLogin(Request, Session);


        Permission per = new Permission(int.Parse(Session["gid"].ToString()));
        if (per.awmag == 0)
            CGeneral.GoToErrorPage(Response, "custom", "YOU NEED MORE POWER");

        if (Request.QueryString["type"]==null)
        {
            CGeneral.GoToErrorPage(Response, "ParamWrong");
        }
        string type = Request.QueryString["type"];

        if (type == "member")
        {
            admin_user.Visible = true;
        }
        else if (type == "forum")
        {
            admin_forum.Visible = true;
        }
        else if (type == "group")
        {
            admin_group.Visible = true;
        }

        getForumList();


    }
    protected void getForumList()
    {
        GetData gd = new GetData();
        List<forums> fo = gd.GetAllForum();
        if (fo.Count() == 0)
            return;
        bool toggle = false;

        foreach (forums f in fo)
        {
            toggle = !toggle;
            if (toggle)
            {
                Literal_forumlist.Text += "<tr class=\"normal\">";
            }else
                Literal_forumlist.Text += "<tr class=\"alter\">";
            Literal_forumlist.Text += "<td><a href=\"editForum.aspx?type=edit&fid=" + f.fid + "\">" + f.fid+ "</a></td>";
            Literal_forumlist.Text += "<td><a href=\"editForum.aspx?type=edit&fid="+f.fid+"\">"+f.name+"</a></td>";
            if(f.visible==1)
                Literal_forumlist.Text += "<td><a href=\"delete.aspx?type=forum&fid="+f.fid+"\">隐藏版块</a></td>";
            else
                Literal_forumlist.Text += "<td><a href=\"delete.aspx?type=forum&fid=" + f.fid + "\">显示版块</a></td>";
        }

    }


    protected void search_user(object sender, EventArgs e)
    {
        bool alter = true;
         GetData gd=new GetData();
         List<members> mem=new List<members>();
        //搜索
         if (this.ziduan.Value == "用户名")
             mem = gd.SearchMemberUsername(keyword.Value);
         else if (this.ziduan.Value == "昵称")
             mem = gd.SearchMemberNickname(keyword.Value);
         else if (this.ziduan.Value == "UID")
             mem.Add(gd.GetOneMember(Check.CheckToInt(keyword.Value)));
         Literal_user_search_result.Text = "";
         foreach (members m in mem)
         {
             string style;
             if (alter)
                 style = "class=\"normal\"";
             else
                 style = "class=\"alter\"";
             alter = !alter;


             if (m != null)
             {
                 Literal_user_search_result.Text += "<tr "+style+"><td><a href=\"" + "profile.aspx?type=info&uid=" + m.uid + "\">" + m.uid + "</a></td>";
                 Literal_user_search_result.Text += "<td><a href=\"" + "profile.aspx?type=info&uid=" + m.uid + "\">" + m.username + "</a></td>";
                 Literal_user_search_result.Text += "<td><a href=\"" + "profile.aspx?type=info&uid=" + m.uid + "\">" + m.nickname + "</a></td>";
                 Literal_user_search_result.Text += "<td><a href=\"" + "profile.aspx?type=info&uid=" + m.uid + "\">" + m.gid + "</a></td>";
                 Literal_user_search_result.Text += "<td><a href=\"" + "delete.aspx?type=user&uid=" + m.uid + "\">删除用户</a></td></tr>";
             }
             
         }

       
    }
}